package day0225;

import java.util.Scanner;

public class Test6 {
    static void create(String [] mes, double[]  ras){
        //for执行3次：mes中存入一个数学公式， 给ras存入对应的正确答案
        for (int i = 0; i < ras.length; i++) {
            double a=(int)(Math.random()*100+1);
            double b=(int)(Math.random()*100+1);
            int type=(int)(Math.random()*4);
            switch(type){
                case 0: mes[i]= a+" + "+b+" =";  ras[i]= a+b;break;
                case 1: mes[i]= a+" - "+b+" =";  ras[i]= a-b;break;
                case 2: mes[i]= a+" * "+b+" =";  ras[i]= a*b;break;
                case 3: mes[i]= a+" / "+b+" =";  ras[i]= a/b;break;
            }
        }
    }


    static void intputAnswersMethod(String []  mes,double[]  ias){
        Scanner s=new Scanner(System.in);
        for (int i = 0; i < ias.length; i++) {
            System.out.println("请输入第" + (i+1) +"道题"+mes[i]+"的答案：");
            ias[i]=s.nextDouble();
        }
    }


    static int judgeAnswers(double[]   ras,double[]   ias){
        int rightCount=0;
        for(int i = 0; i < ias.length; i++){
            if(ras[i] == ias[i]){
                rightCount++;
            }
        }
        return rightCount;
    }


    public static void main(String[] args) {
        String []  mathExpressions={"","",""};
        double[]   ranAnswers={ 0,  0,  0};
        create(mathExpressions,ranAnswers);//1.

        double[]   inputAnswers={ 0,  0,  0};//2.
        intputAnswersMethod(mathExpressions,inputAnswers);

        int c=judgeAnswers(ranAnswers,inputAnswers);//3.
        System.out.println("回答对的数目："+c);
    }



}
